package com.just.sxmiaosha.dao;

import com.just.sxmiaosha.entity.Stock;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author just
 * @since 2020-09-23
 */
public interface StockDao extends  BaseMapper<Stock> {

    @Select("select * from stock where id=#{id}")
    Stock getStockCountById(int id);

    @Update("update stock set sale=(sale+#{count}) where id=#{sid} ")
    void updateStock(int sid, int count);

    @Update("update stock set sale=sale+#{count} where id=#{sid} and sale=#{sale}")
    int updateByOptimistic(int sid, int count,int sale);

    @Select("select * from stock where id=#{sid} for update ")
    Stock getStockByIdForUpdate(int sid);

    @Update("update stock set sale=#{sale} where id=#{id}")
    void updateSaleStock(Integer id, int sale);
}
